﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.WindowsAPICodePack.Shell;
using TouchControls;

namespace TouchExplorer.Views
{
    /// <summary>
    /// Interaction logic for Welcome.xaml
    /// </summary>
    public partial class Welcome : UserControl
    {
        public Welcome()
        {
            InitializeComponent();
            Loaded += (sender, args) =>
                {
                    Favorites.ItemsSource = App.Current.Favorites.Elements;
                    var lst = new List<TouchFileElementBase>();
                    lst.Add(new TouchDirectory(KnownFolders.DocumentsLibrary as ShellObject));
                    lst.Add(new TouchDirectory(KnownFolders.MusicLibrary as ShellObject));
                    lst.Add(new TouchDirectory(KnownFolders.PicturesLibrary as ShellObject));
                    lst.Add(new TouchDirectory(KnownFolders.VideosLibrary as ShellObject));
                    lst.Add(new TouchDirectory(KnownFolders.Downloads as ShellObject));
                    lst.Add(new TouchDirectory(KnownFolders.Computer as ShellObject));
                    Preset.ItemsSource = lst;
                };
        }

        private void TileClick(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            
            (Application.Current as App).BrowseFolder(btn.CommandParameter as string);
        }

        public void RemoveFavorite(object sender, RoutedEventArgs e)
        {
            var item = sender as TouchMenuItem;
            var elt = item.DataContext as TouchFileElementBase;
            if (elt != null)
            {
                App.Current.Favorites.Remove(elt);
            }
        }

        public void ShowMenu(object sender, MouseButtonEventArgs e)
        {
            var btn = sender as Button;
            CtxMenu.ShowMenu(btn);
        }

        private void StartFavorite(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            var elt = btn.DataContext as TouchFileElementBase;

            if (elt is TouchFile)
            {
                var file = elt as TouchFile;
                file.Run();
            }
            else
            {
                (Application.Current as App).BrowseFolder(elt.FullPath);
            }
        }
    }
}
